package app.action;

import java.awt.event.ActionEvent;
import java.io.File;

import javax.swing.JFileChooser;

import app.ui.AbsCommonPanel;
import app.ui.MainFrame;
import app.ui.MakeDataFileUi;

public class SaveDataFile extends AbsCommonPanelAction {
	private JFileChooser jFileChooser;
	private File file;
	private String fileName = "Test_N.dat";

	public SaveDataFile(AbsCommonPanel mPanel) {
		super(mPanel);
		String currentDirectoryPath = mPanel.getmFrame().getAppProp().getProperty(MainFrame.LASTDIR);
		this.jFileChooser = new JFileChooser(currentDirectoryPath);
		// jFileChooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
	}

	public void actionPerformed(ActionEvent e) {
		int num = jFileChooser.showDialog(mPanel, "Save");

		if (num == JFileChooser.APPROVE_OPTION) {
			this.file = jFileChooser.getSelectedFile();
			this.fileName = file.getName();
			doSpecificPanelAction();
		}
	}

	@Override
	protected void doSpecificPanelAction() {
		MakeDataFileUi mDF = (MakeDataFileUi) mPanel;
		mDF.getExHelper().setSaveToPath(file.getParent());
		mDF.getExHelper().saveFileData(fileName, mDF.getjTextFields()[0].getText());
	}

}
